import React from 'react';
import { ts2Formatter,renderState } from 'utils';
import moment from 'moment';
import { actions } from 'mirrorx';
{/*
可配置化种类：

1、表格头部字段 
    1、列表页表格头部字段集合 mainTableColumn
    2、编辑页表格头部字段集合 childTableColumn

2、编辑框的字段
    1、编辑页 直接显示在页面的编辑字段 FormField
    2、编辑页 需要点击表格的增行弹框编辑的字段 FormTableField
    3. 列表页查询区域  searchField

3.表头部的按钮  headerButtonSets

4.表行尾部按钮  columnButtonSets
*/}

//表头信息

//字段属性

//基本信息
const FormDataHeader = [
        {
            enname: "vbillCode",
            zhname: "单据号",
            type:"FormControl",
            edit:{0:false,1:false},
            hidepage:{0:true}
        },
        {
            enname: "billStatusId",
            codename: "billStatusCode",
            showname: "billStatusName",
            zhname: "单据状态",
            type: "Select",
            code:"BILL_STATUS",
            hidepage: { 0: true },
            edit:false,
            required: true,
        },
        {
            enname:"creationTime",
            zhname:"单据日期",
            type: "DatePicker",
            format:"YYYY-MM-DD",
            hidepage:{0:true},
            edit:false,
        },
        {
            enname: "pkOrgId",
            showname: "pkOrgName",
            codename: "pkOrgCode",
            zhname: "隶属组织",
            multiple: true,
            param:{
                "AUTH_refdim":"pkOrg","AUTH_refcod":"B2B_RETAIL_MONTHLYPLAN"
            },
            cascadeChildTable:[{
                refKey: "refpk", 
                dtoKey: "branchbfficeId",
                childType:"retailMonthlyplanItem" 
            }],
            type: "RefComponent",
            refname: "organization",
            edit: true,
            required: true,
        },
        {
            enname: "setDimensionId",
            codename: "setDimensionCode",
            showname: "setDimensionName",
            zhname: "设置维度1",
            type: "Select",
            showcontrol: [{
                value: "01",
                refKey: "code",
                dtoKey: "setDimensionCode",
                layer: ["childTableColumn", "retailMonthlyplanItem", "column"],
                fields: ["brandName","categoryName"]
            },{
                value: "02",
                refKey: "code",
                dtoKey: "setDimensionCode",
                layer: ["childTableColumn", "retailMonthlyplanItem", "column"],
                fields: ["modelName"]
            }],
            code:"SZWDA",
            edit:true,
            required: false,
        },
        {
            enname: "setDimension1Id",
            codename: "setDimension1Code",
            showname: "setDimension1Name",
            zhname: "设置维度2",
            type: "Select",
            showcontrol: [{
                value: "01",
                refKey: "code",
                dtoKey: "setDimension1Code",
                layer: ["childTableColumn", "retailMonthlyplanItem", "column"],
                fields: ["storeName"]
            },{
                value: "02",
                refKey: "code",
                dtoKey: "setDimension1Code",
                layer: ["FormField", "DataHeader", "Field"],
                fields: ["salesAreaId", "channelId"]
            }],
            code:"SZWDA1",
            edit:true,
            required: false,
        },
        {
            enname: "salesAreaId",
            codename: "salesAreaCode",
            showname: "salesAreaName",
            zhname: "零售片区",
            type: "RefComponent",
            param:{
                AUTH_refdim : "salesArea",
                AUTH_refcod : "B2B_RETAIL_MONTHLYPLAN",
                "EQ_enableState":"0",
            },
            edit:true,
            refname:"departmentRef",
            required: false,
        },
        {
            enname:"ext01Name",
            zhname:"零售地区",
            required: false,
            hidepage:{0:true,1:true,2:false},
            type: "FormControl",
            edit: false
        },
        {
            enname:"ext02Name",
            zhname:"零售大区",
            required: false,
            hidepage:{0:true,1:true,2:false},
            type: "FormControl",
            edit: false
        },
        {
            enname: "channelId",
            codename: "channelCode",
            showname: "channelName",
            zhname: "渠道",
            type: "RefComponent",
            // multiple:true,
            param:{
                AUTH_refdim : "channel",
                AUTH_refcod : "B2B_RETAIL_MONTHLYPLAN",
                "EQ_enableState": "1",
            },
            edit:true,
            refname:"custchantype",
            required: false,
        },
        {
            enname: "billMakerName",
            zhname: "制单人",
            type: "FormControl",
            hidepage:{0:true},
            edit:false,
            required: false,
        },
        {
            enname: "targetDimension",
            zhname: "目标维度",
            type: "Radio",
            options: [{
                "key": 1,
                "value": "月度目标"
            }, {
                "key": 0,
                "value": "活动目标"
            }],
            showcontrol: [{
                value: 1,
                refKey: "value",
                dtoKey: "targetDimension",
                layer: ["FormField", "DataHeader", "Field"],
                fields: ["monthPlan"]
            },{
                value: 1,
                refKey: "value",
                dtoKey: "targetDimension",
                hideFlag:true,
                layer: ["FormField", "DataHeader", "Field"],
                fields: ["activityStartDate","activityEndDate"]
            }],
            edit: true,
            required: true,
        },
        {
            enname: "monthPlan",
            zhname: "计划月度",
            type: "DatePicker",
            format:"YYYY-MM",
            required: false,
            edit: true,
        },
        {
            enname:"activityStartDate",
            zhname:"活动开始日期",
            type: "DatePicker",
            format:"YYYY-MM-DD",
            edit: true
        },
        {
            enname: "activityEndDate",
            zhname: "活动截止日期",
            type: "DatePicker",
            disabledDate:"activityStartDate",
            format:"YYYY-MM-DD",
            edit:true,
        },
        {
            enname: "amount",
            zhname: "金额",
            type: "InputNumber",
            edit: false,
        },
        {
            enname: "num",
            zhname: "数量",
            type: "InputNumber",
            edit: false,
        },
        {
            enname: "remark",
            zhname: "备注",
            type: "FormControl",
            pattern:/^\S*$/,
            message: "不能有空格",
            edit: true,
        }
];
const columnretailMonthlyplanItem = [
    {
        title: "门店",
        dataIndex: "storeName",
        key: "storeId",
        renderType: "refcomponent",
        validate: false,
        required:true,
        filedProps: {
            title: "门店",
            refName: "terminal",
            aliasparam: [{
                paramkey: "EQ_organization.id",
                alias: "pkOrgId",
            }],
            fieldName: "storeName",
            reffields: { refpk: "storeId", refname: "storeName", refcode: "storeCode" }
        },
    },
    {
        title: "品牌",
        dataIndex: "brandName",
        key: "brandId",
        renderType: "refcomponent",
        width: 200,
        hideFlag:true,
        filedProps: {
            title: "品牌",
            refName: "brandref",
            fieldName: "brandName",
            reffields: { refpk: "brandId", refname: "brandName", refcode: "brandCode" }
        },
    },
    {
        title: "品类",
        dataIndex: "categoryName",
        key: "categoryId",
        renderType: "refcomponent",
        width: 200,
        filedProps: {
            title: "商品品类",
            refName: "terminalGoodsCate",
            fieldName: "categoryName",
            reffields: { refpk: "categoryId", refname: "categoryName", refcode: "categoryCode" }
        },
    },
    {
        title: "型号",
        dataIndex: "modelName",
        key: "modelId",
        renderType: "refcomponent",
        width: 200,
        filedProps: {
            title: "型号",
            refName: "goodsRef",
            fieldName: "modelName",
            reffields: { refpk: "modelId", refname: "modelName", refcode: "modelCode" }
        },
    },
    {
        title: "数量",
        dataIndex: "num",
        key: "num",
        renderType: "inputnumber",
        width: 200,
        required:true,
        validate:false,
        filedProps: {
            precision:0,
            except:0,
            min: 0,
        },
        validate: false,
    },
    {
        title: "金额",
        dataIndex: "amount",
        key: "amount",
        width: 120,
        required:true,
        validate:false,
        renderType: "inputnumber",
        filedProps: {
            precision:2,
            except:0,
            min: 0,
        }
    },
    {
        dataIndex: "remark",
        key: "remark",
        title: "备注",
        renderType: "input",
        pattern:/^\S*$/,
        patternMessage: "不能有空格",
        filedProps: {
            maxLength:20,
        },
        edit: true,
        required: false,
    }
]
//表单字段

export const FormField = {
    "DataHeader": {
        "title": "基础信息",
        "Field": FormDataHeader
    },
}

//表格弹框表单字段
export const FormTableField = {
}

//渲染成字表表格的头
export const childTableColumn = {
    "retailMonthlyplanItem": {
        "title": "明细",
        "type": "grid",
        "column": columnretailMonthlyplanItem
    },
}

//渲染成字表表格的头
export const mainTableColumn = [
    {
        title: "单据号",
        dataIndex: "vbillCode",
        key: "vbillCode",
        width:140,
        render: (text, record) => {
            return <a style={{ "cursor": "pointer" }}
                onClick={() => {
                    actions.routing.push(
                        {
                            pathname: 'RetailOrdersMonth-edit',
                            search: `?search_id=${record.id}&btnPageFlag=2`,
                        }
                    );
                    // location.reload();
                }}
            >
                {text}
            </a >;
        }
    },
    {
        title: "零售片区",
        dataIndex: "salesAreaName",
        key: "salesAreaName",
        width:120,
    },
    {
        title: "维度1",
        dataIndex: "setDimensionName",
        key: "setDimensionId",
        width:100,
    },
    {
        title: "维度2",
        dataIndex: "setDimension1Name",
        key: "setDimension1Id",
        width:100,
    },
    {
        title: "月度",
        dataIndex: "monthPlan",
        key: "monthPlan",
        width:100,
        render:(text, record, index)=> {
            return text && moment(text).format("YYYY-MM");
        }
    },
    {
        title: "渠道",
        dataIndex: "channelName",
        width: 100,
        key: "channelName",
    },
    {
        title: "活动起止日期",
        dataIndex: "activityStartDate",
        width: 100,
        key: "activityStartDate",
        render(text, record, index) {
            return (text ? ts2Formatter(text) : text)
        },
    },
    {
        title: "数量",
        dataIndex: "num",
        width: 120,
        key: "num",
    },
    {
        title: "金额",
        dataIndex: "amount",
        width: 120,
        key: "amount",
    },
    {
        title: "单据状态",
        dataIndex: "state",
        width: 110,
        key: "state",
        render:(text)=> {
            return renderState(text);
        }
    }
]

export const searchField = [
    {
        enname: "activityStartDate",
        zhname: "活动起止日期",
        type: "RangePicker",
        rangeField:["activityStartDate","activityStartDate"],
        edit:true,
    },
    {
        enname:"vbillCode",
        zhname:"单据号",
        searchType:"like",
        type: "FormControl",
        edit: true
    },
    {
        enname:"billMaker",
        zhname:"制单人",
        required: false,
        realRef:true,
        refname:"personRef",
        type: "RefComponent",
        edit: true
    },
    {
        enname: "salesArea",
        zhname: "零售片区",
        required: false,
        refname:"departmentRef",
        type: "RefComponent",
        realRef:true,
        edit: true
    },
    {
        enname: "ext01",
        zhname: "零售地区",
        required: false,
        refname:"departmentRef",
        type: "RefComponent",
        realRef:true,
        edit: true
    },
    {
        enname: "ext02",
        zhname: "零售大区",
        required: false,
        refname:"departmentRef",
        type: "RefComponent",
        realRef:true,
        edit: true
    },
    {
        enname: "setDimension",
        zhname: "设置维度1",
        type: "Select",
        code:"SZWDA",
        edit: true
    },
    {
        enname: "setDimension1",
        zhname: "设置维度2",
        type: "Select",
        code:"SZWDA1",
        edit: true
    },
    {
        enname: "state",
        zhname: "审批状态",
        type: "Select",
        code: "BILL_STATUS",
        required: false,
        edit:true,
    }
]

export const headerButtonSets = [
    {
        event: "ButtonAdd",
        zhname: "新增",
        color: 'primary',
        authcode: "001",
    }
]

export const columnButtonSets = {
    "delete": {
        event: "ButtonDel",
        zhname: "删除",
        batch: true,
        method: "post",
        ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
        url: 'occ-b2b-order/b2b/retail-monthlyplans/deleteOrder'
    },
    "edit": true,
    "detail": true
}

// export default {mainTableColumn,searchField,headerButtonSets,
//     columnButtonSets,childTableColumn,FormTableField,FormField}
export const SelectCode = ["BILL_STATUS","ls002","ls001","sale","BILL_STATUS","HSFS","SZWDA","SZWDA1"]
